package com.candy.control;

import com.candy.bean.UserInfo;
import com.candy.service.UserinfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Api("用户信息管理")
@RestController
@RequestMapping("/userinfo")
public class UserInfoController {
    @Autowired
    UserinfoService userinfoService;

    /**
     * 查询获取全部未删除的信息；进行分页处理
     * @param userInfo
     * @return
     */
    @RequestMapping("/getallinfoes")
    public PageInfo<UserInfo> getAllInfoes(Integer pageNum,Integer pageSize,UserInfo userInfo){
        System.out.println("pageNum:::"+pageNum);
        System.out.println("pageSize:::"+pageSize);
        PageHelper.startPage(pageNum,pageSize);
//        pageHelper.startPage下面的第一个查询会进行分页处理
        List<UserInfo> lst=userinfoService.getAllInfoes(userInfo);
        PageInfo<UserInfo> pageInfo=new PageInfo<>(lst);
        System.out.println("pagehelper:::::::::::::::::::");
        System.out.println("total:"+pageInfo.getTotal());
        System.out.println("size:"+pageInfo.getSize());
        System.out.println("list:"+pageInfo.getList());
        System.out.println("pageInfo:"+pageInfo);
        return pageInfo;
    }

    /**
     * 新增或编辑方法；影响行数大于0；数据更新成功返回ok；反之返回eg
     * @param userInfo
     * @return
     */
    @RequestMapping("/addorupdateuser")
    public String addOrUpdateUser(UserInfo userInfo){
        Integer num=userinfoService.addOrUpdateUser(userInfo);
        if(num>0){
            return "ok";
        }else {
            return "eg";
        }

    }

    /**
     * 删除方法；影响行数大于0；数据更新成功返回ok；反之返回eg
     * @param userInfo
     * @return
     */
    @RequestMapping("/deleteuser")
    public String deleteUser(UserInfo userInfo){
        Integer num=userinfoService.deleteUser(userInfo);
        if(num>0){
            return "ok";
        }else {
            return "eg";
        }

    }


}
